package br.com.funaction.eventtcontrollerv2.model;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Connection;

import br.com.funaction.eventtcontrollerv2.entities.Franquia;
import br.com.funaction.eventtcontrollerv2.util.ConexaoUtil;

public class LoginDAO implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final String SELECT = "SELECT * FROM " + 
			"funactio_eventt_controller.franquia WHERE EMAIL=? AND SENHA=?;";
	
	Connection con = null;
	PreparedStatement prepStmt = null;
	ResultSet rs = null;
	
	public Boolean verificaCredencial(String email, String senha) throws SQLException{
		
		Boolean temCredencial = false;
		
		con = ConexaoUtil.getConexao();
		prepStmt = con.prepareStatement(SELECT);
		prepStmt.setString(1, email);
		prepStmt.setString(2, senha);
		rs = prepStmt.executeQuery();
		
		while(rs.next()){
			
			temCredencial = true;
		}
		
		return temCredencial;
	}
	
	public Franquia dadosFranquia(String email, String senha) throws SQLException{
		
		Franquia franquia = new Franquia();
		
		con = ConexaoUtil.getConexao();
		prepStmt = con.prepareStatement(SELECT);
		prepStmt.setString(1, email);
		prepStmt.setString(2, senha);
		rs = prepStmt.executeQuery();
		
		while(rs.next()){
			
			franquia.setId(rs.getInt("ID"));
			franquia.setCidade(rs.getString("CIDADE"));
			franquia.setEstado(rs.getString("ESTADO"));
			franquia.setEmail(rs.getString("EMAIL"));
			franquia.setSenha(rs.getString("SENHA"));
		}
		
		return franquia;
	}
}